package o;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.f;
import androidx.recyclerview.widget.RecyclerView.g;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.t;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;

@VisibleForTesting
public class mf extends f implements g {
    private static final int[] ˊॱ = new int[0];
    private static final int[] ͺ = new int[]{16842919};
    @VisibleForTesting
    int ʻ;
    private final int ʻॱ;
    @VisibleForTesting
    float ʼ;
    private RecyclerView ʼॱ;
    @VisibleForTesting
    int ʽ;
    private int ʽॱ = 0;
    private boolean ʾ = false;
    private int ʿ = 0;
    private boolean ˈ = false;
    private final int[] ˉ = new int[2];
    final Drawable ˊ;
    private int ˊˊ = 0;
    private final int[] ˊˋ = new int[2];
    private final Runnable ˊᐝ = new Runnable(this) {
        final /* synthetic */ mf ॱ;

        {
            this.ॱ = r1;
        }

        public void run() {
            this.ॱ.ॱ((int) IPRoute.INTERVAL);
        }
    };
    @VisibleForTesting
    float ˋ;
    private int ˋˊ = 0;
    private final int ˋॱ;
    private final n ˌ = new n(this) {
        final /* synthetic */ mf ˏ;

        {
            this.ˏ = r1;
        }

        public void ˊ(RecyclerView recyclerView, int i, int i2) {
            this.ˏ.ˋ(recyclerView.computeHorizontalScrollOffset(), recyclerView.computeVerticalScrollOffset());
        }
    };
    @VisibleForTesting
    int ˎ;
    final StateListDrawable ˏ;
    private final int ˏॱ;
    @VisibleForTesting
    int ॱ;
    private final int ॱˊ;
    private final Drawable ॱˋ;
    private final int ॱˎ;
    int ॱॱ = 0;
    private final StateListDrawable ॱᐝ;
    final ValueAnimator ᐝ = ValueAnimator.ofFloat(new float[]{0.0f, 1.0f});
    private final int ᐝॱ;

    class a extends AnimatorListenerAdapter {
        final /* synthetic */ mf ˏ;
        private boolean ॱ = false;

        a(mf mfVar) {
            this.ˏ = mfVar;
        }

        public void onAnimationEnd(Animator animator) {
            if (this.ॱ) {
                this.ॱ = false;
            } else if (((Float) this.ˏ.ᐝ.getAnimatedValue()).floatValue() == 0.0f) {
                this.ˏ.ॱॱ = 0;
                this.ˏ.ˏ(0);
            } else {
                this.ˏ.ॱॱ = 2;
                this.ˏ.ˏ();
            }
        }

        public void onAnimationCancel(Animator animator) {
            this.ॱ = true;
        }
    }

    class d implements AnimatorUpdateListener {
        final /* synthetic */ mf ˏ;

        d(mf mfVar) {
            this.ˏ = mfVar;
        }

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int floatValue = (int) (((Float) valueAnimator.getAnimatedValue()).floatValue() * 255.0f);
            this.ˏ.ˏ.setAlpha(floatValue);
            this.ˏ.ˊ.setAlpha(floatValue);
            this.ˏ.ˏ();
        }
    }

    public mf(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i, int i2, int i3) {
        this.ˏ = stateListDrawable;
        this.ˊ = drawable;
        this.ॱᐝ = stateListDrawable2;
        this.ॱˋ = drawable2;
        this.ˏॱ = Math.max(i, stateListDrawable.getIntrinsicWidth());
        this.ॱˎ = Math.max(i, drawable.getIntrinsicWidth());
        this.ʻॱ = Math.max(i, stateListDrawable2.getIntrinsicWidth());
        this.ᐝॱ = Math.max(i, drawable2.getIntrinsicWidth());
        this.ॱˊ = i2;
        this.ˋॱ = i3;
        this.ˏ.setAlpha(255);
        this.ˊ.setAlpha(255);
        this.ᐝ.addListener(new a(this));
        this.ᐝ.addUpdateListener(new d(this));
        ˎ(recyclerView);
    }

    public void ˎ(@Nullable RecyclerView recyclerView) {
        if (this.ʼॱ != recyclerView) {
            if (this.ʼॱ != null) {
                ˊ();
            }
            this.ʼॱ = recyclerView;
            if (this.ʼॱ != null) {
                ˋ();
            }
        }
    }

    private void ˋ() {
        this.ʼॱ.ॱ(this);
        this.ʼॱ.ˏ(this);
        this.ʼॱ.ॱ(this.ˌ);
    }

    private void ˊ() {
        this.ʼॱ.ˏ(this);
        this.ʼॱ.ॱ(this);
        this.ʼॱ.ˏ(this.ˌ);
        ʻ();
    }

    void ˏ() {
        this.ʼॱ.invalidate();
    }

    void ˏ(int i) {
        if (i == 2 && this.ˋˊ != 2) {
            this.ˏ.setState(ͺ);
            ʻ();
        }
        if (i == 0) {
            ˏ();
        } else {
            ˎ();
        }
        if (this.ˋˊ == 2 && i != 2) {
            this.ˏ.setState(ˊॱ);
            ˊ(1200);
        } else if (i == 1) {
            ˊ(1500);
        }
        this.ˋˊ = i;
    }

    private boolean ॱ() {
        return ViewCompat.ʼ(this.ʼॱ) == 1;
    }

    public void ˎ() {
        switch (this.ॱॱ) {
            case 0:
                break;
            case 3:
                this.ᐝ.cancel();
                break;
            default:
                return;
        }
        this.ॱॱ = 1;
        this.ᐝ.setFloatValues(new float[]{((Float) this.ᐝ.getAnimatedValue()).floatValue(), 1.0f});
        this.ᐝ.setDuration(500);
        this.ᐝ.setStartDelay(0);
        this.ᐝ.start();
    }

    @VisibleForTesting
    void ॱ(int i) {
        switch (this.ॱॱ) {
            case 1:
                this.ᐝ.cancel();
                break;
            case 2:
                break;
            default:
                return;
        }
        this.ॱॱ = 3;
        this.ᐝ.setFloatValues(new float[]{((Float) this.ᐝ.getAnimatedValue()).floatValue(), 0.0f});
        this.ᐝ.setDuration((long) i);
        this.ᐝ.start();
    }

    private void ʻ() {
        this.ʼॱ.removeCallbacks(this.ˊᐝ);
    }

    private void ˊ(int i) {
        ʻ();
        this.ʼॱ.postDelayed(this.ˊᐝ, (long) i);
    }

    public void ˋ(Canvas canvas, RecyclerView recyclerView, t tVar) {
        if (this.ʿ != this.ʼॱ.getWidth() || this.ʽॱ != this.ʼॱ.getHeight()) {
            this.ʿ = this.ʼॱ.getWidth();
            this.ʽॱ = this.ʼॱ.getHeight();
            ˏ(0);
        } else if (this.ॱॱ != 0) {
            if (this.ʾ) {
                ˏ(canvas);
            }
            if (this.ˈ) {
                ˋ(canvas);
            }
        }
    }

    private void ˏ(Canvas canvas) {
        int i = this.ʿ - this.ˏॱ;
        int i2 = this.ॱ - (this.ˎ / 2);
        this.ˏ.setBounds(0, 0, this.ˏॱ, this.ˎ);
        this.ˊ.setBounds(0, 0, this.ॱˎ, this.ʽॱ);
        if (ॱ()) {
            this.ˊ.draw(canvas);
            canvas.translate((float) this.ˏॱ, (float) i2);
            canvas.scale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
            this.ˏ.draw(canvas);
            canvas.scale(1.0f, 1.0f);
            canvas.translate((float) (-this.ˏॱ), (float) (-i2));
            return;
        }
        canvas.translate((float) i, 0.0f);
        this.ˊ.draw(canvas);
        canvas.translate(0.0f, (float) i2);
        this.ˏ.draw(canvas);
        canvas.translate((float) (-i), (float) (-i2));
    }

    private void ˋ(Canvas canvas) {
        int i = this.ʽॱ - this.ʻॱ;
        int i2 = this.ʻ - (this.ʽ / 2);
        this.ॱᐝ.setBounds(0, 0, this.ʽ, this.ʻॱ);
        this.ॱˋ.setBounds(0, 0, this.ʿ, this.ᐝॱ);
        canvas.translate(0.0f, (float) i);
        this.ॱˋ.draw(canvas);
        canvas.translate((float) i2, 0.0f);
        this.ॱᐝ.draw(canvas);
        canvas.translate((float) (-i2), (float) (-i));
    }

    void ˋ(int i, int i2) {
        int computeVerticalScrollRange = this.ʼॱ.computeVerticalScrollRange();
        int i3 = this.ʽॱ;
        boolean z = computeVerticalScrollRange - i3 > 0 && this.ʽॱ >= this.ॱˊ;
        this.ʾ = z;
        int computeHorizontalScrollRange = this.ʼॱ.computeHorizontalScrollRange();
        int i4 = this.ʿ;
        if (computeHorizontalScrollRange - i4 <= 0 || this.ʿ < this.ॱˊ) {
            z = false;
        } else {
            z = true;
        }
        this.ˈ = z;
        if (this.ʾ || this.ˈ) {
            if (this.ʾ) {
                this.ॱ = (int) (((((float) i2) + (((float) i3) / 2.0f)) * ((float) i3)) / ((float) computeVerticalScrollRange));
                this.ˎ = Math.min(i3, (i3 * i3) / computeVerticalScrollRange);
            }
            if (this.ˈ) {
                this.ʻ = (int) (((((float) i) + (((float) i4) / 2.0f)) * ((float) i4)) / ((float) computeHorizontalScrollRange));
                this.ʽ = Math.min(i4, (i4 * i4) / computeHorizontalScrollRange);
            }
            if (this.ˋˊ == 0 || this.ˋˊ == 1) {
                ˏ(1);
            }
        } else if (this.ˋˊ != 0) {
            ˏ(0);
        }
    }

    public boolean ˋ(@NonNull RecyclerView recyclerView, @NonNull MotionEvent motionEvent) {
        if (this.ˋˊ == 1) {
            boolean ॱ = ॱ(motionEvent.getX(), motionEvent.getY());
            boolean ˏ = ˏ(motionEvent.getX(), motionEvent.getY());
            if (motionEvent.getAction() != 0 || (!ॱ && !ˏ)) {
                return false;
            }
            if (ˏ) {
                this.ˊˊ = 1;
                this.ʼ = (float) ((int) motionEvent.getX());
            } else if (ॱ) {
                this.ˊˊ = 2;
                this.ˋ = (float) ((int) motionEvent.getY());
            }
            ˏ(2);
            return true;
        } else if (this.ˋˊ != 2) {
            return false;
        } else {
            return true;
        }
    }

    public void ॱ(@NonNull RecyclerView recyclerView, @NonNull MotionEvent motionEvent) {
        if (this.ˋˊ != 0) {
            if (motionEvent.getAction() == 0) {
                boolean ॱ = ॱ(motionEvent.getX(), motionEvent.getY());
                boolean ˏ = ˏ(motionEvent.getX(), motionEvent.getY());
                if (ॱ || ˏ) {
                    if (ˏ) {
                        this.ˊˊ = 1;
                        this.ʼ = (float) ((int) motionEvent.getX());
                    } else if (ॱ) {
                        this.ˊˊ = 2;
                        this.ˋ = (float) ((int) motionEvent.getY());
                    }
                    ˏ(2);
                }
            } else if (motionEvent.getAction() == 1 && this.ˋˊ == 2) {
                this.ˋ = 0.0f;
                this.ʼ = 0.0f;
                ˏ(1);
                this.ˊˊ = 0;
            } else if (motionEvent.getAction() == 2 && this.ˋˊ == 2) {
                ˎ();
                if (this.ˊˊ == 1) {
                    ॱ(motionEvent.getX());
                }
                if (this.ˊˊ == 2) {
                    ˊ(motionEvent.getY());
                }
            }
        }
    }

    public void ˎ(boolean z) {
    }

    private void ˊ(float f) {
        int[] ॱॱ = ॱॱ();
        float max = Math.max((float) ॱॱ[0], Math.min((float) ॱॱ[1], f));
        if (Math.abs(((float) this.ॱ) - max) >= 2.0f) {
            int ॱ = ॱ(this.ˋ, max, ॱॱ, this.ʼॱ.computeVerticalScrollRange(), this.ʼॱ.computeVerticalScrollOffset(), this.ʽॱ);
            if (ॱ != 0) {
                this.ʼॱ.scrollBy(0, ॱ);
            }
            this.ˋ = max;
        }
    }

    private void ॱ(float f) {
        int[] ʼ = ʼ();
        float max = Math.max((float) ʼ[0], Math.min((float) ʼ[1], f));
        if (Math.abs(((float) this.ʻ) - max) >= 2.0f) {
            int ॱ = ॱ(this.ʼ, max, ʼ, this.ʼॱ.computeHorizontalScrollRange(), this.ʼॱ.computeHorizontalScrollOffset(), this.ʿ);
            if (ॱ != 0) {
                this.ʼॱ.scrollBy(ॱ, 0);
            }
            this.ʼ = max;
        }
    }

    private int ॱ(float f, float f2, int[] iArr, int i, int i2, int i3) {
        int i4 = iArr[1] - iArr[0];
        if (i4 == 0) {
            return 0;
        }
        int i5 = i - i3;
        i4 = (int) (((f2 - f) / ((float) i4)) * ((float) i5));
        int i6 = i2 + i4;
        if (i6 >= i5 || i6 < 0) {
            return 0;
        }
        return i4;
    }

    @VisibleForTesting
    boolean ॱ(float f, float f2) {
        if (ॱ() ? f <= ((float) (this.ˏॱ / 2)) : f >= ((float) (this.ʿ - this.ˏॱ))) {
            if (f2 >= ((float) (this.ॱ - (this.ˎ / 2))) && f2 <= ((float) (this.ॱ + (this.ˎ / 2)))) {
                return true;
            }
        }
        return false;
    }

    @VisibleForTesting
    boolean ˏ(float f, float f2) {
        return f2 >= ((float) (this.ʽॱ - this.ʻॱ)) && f >= ((float) (this.ʻ - (this.ʽ / 2))) && f <= ((float) (this.ʻ + (this.ʽ / 2)));
    }

    private int[] ॱॱ() {
        this.ˉ[0] = this.ˋॱ;
        this.ˉ[1] = this.ʽॱ - this.ˋॱ;
        return this.ˉ;
    }

    private int[] ʼ() {
        this.ˊˋ[0] = this.ˋॱ;
        this.ˊˋ[1] = this.ʿ - this.ˋॱ;
        return this.ˊˋ;
    }
}
